/*
 * @lc app=leetcode.cn id=976 lang=typescript
 *
 * [976] 三角形的最大周长
 */

// @lc code=start

// 排序法
function largestPerimeter(nums: number[]): number {
    const sorted = nums.sort((a, b) => b - a);
    let now: number[] = [];
    for (let i = 2; i < sorted.length; i++) {
        now = sorted.slice(i - 2, i + 1);
        let [a, b, c] = now;
        if (a < b + c) {
            return now.reduce((a, b) => a + b, 0);
        }
    }
    return 0;
}
// @lc code=end
